/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ted;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class GetSrc {

    public static List<String> getSrc() {
      String result = "";
      String address = "http://video.shishicai.cn/haoma/cqssc/list/120.aspx";
		try {
			URL url = new URL(address);
			URLConnection conn = url.openConnection();
			conn.setRequestProperty("User-Agent",
					"Mozilla/4.0 (compatible; MSIE 7.0; NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)");
			conn.setRequestProperty("Accept-Language", "GB2312");
			BufferedReader br = new BufferedReader(new InputStreamReader(
					conn.getInputStream(), "GB2312"));
			String str = br.readLine();
			while (str != null) {
				if (str.indexOf("listIssue ") != -1) {
					result += str;
				}
				str = br.readLine();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
        }
      String se = result.substring(21, result.length()-3);
      String ss[] = se.split("},");
      List<String>resList = new ArrayList<String>();
      for(String s : ss){
          resList.add(s.substring(s.length()-9,s.length()-1)+"--"+s.substring(22,31)+"--"+s.substring(61,66));
      }

      List<String> tempList = new ArrayList<String>();
		int j = 0;
		for (int i = resList.size() - 1; i >= 0; i--) {
			tempList.add(j, resList.get(i));
			j++;
		}
		return tempList;
 
    }

    public static List<Integer> getSingleNum(List<String> tmpList, int seat) {
        List<Integer> resList = new ArrayList<Integer>();

        for (String s : tmpList) {
            String sa[] = s.split("--");
//             System.out.println(sa[0]);
            String sb[] = sa[1].split(",");
//            System.out.println(sb[0]);
            resList.add(Integer.valueOf(sb[seat]));
        }
       
        return resList;
    }

    public static List<Integer> readLocalFile(int seat) {
        String filename = "src/ted/cqssc.txt";
        File file = new File(filename);
        BufferedReader reader = null;
        List<Integer> numList = new ArrayList<Integer>();
        List<Integer> tempList = new ArrayList<Integer>();
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
//                System.out.println( tempString);
                String[] temp = tempString.split(" ");
                String temp2 = temp[1];
                String[] temp3 = temp2.split(",");
                int num = Integer.parseInt(temp3[seat]);
                numList.add(num);
            }
            reader.close();

        } catch (IOException e) {
            System.out.println(e.getMessage());
            System.err.println("read file error!!!");

        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        tempList = ListUtil.revertList(numList);
        return tempList;
    }

    public static void main(String args[]) {

    readLocalFile(2);
    }
}
